package com.lxm.controller;


import com.lxm.dto.CommentDTO;
import com.lxm.dto.Result;
import com.lxm.service.LxmCommentService;
import com.lxm.vo.CommentDetailVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 评论表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2024-10-02
 */
@RestController
@RequestMapping("/user/comment")
@Tag(name = "评论管理")
public class LxmCommentController {
    @Resource
    private LxmCommentService lxmCommentService;

    @Operation(summary = "新增评论")
    @PostMapping("/add")
    public Result addComment(@RequestBody CommentDTO commentDTO) {

        return lxmCommentService.addComment(commentDTO);
    }

    @Operation(summary = "删除评论", description = "可以自己选择删除几个评论")
    @DeleteMapping("/delete")
    public Result deleteComments(@RequestBody List<Long> commentIds) {
        return lxmCommentService.deleteComment(commentIds);
    }

    @Operation(summary = "分页获取自己历史评论列表", description = "这个用于用户查询自己的评论历史")
    @GetMapping("/listByMe")
    public Result getCommentList(@RequestParam(name = "current", defaultValue = "1")
                                 Integer current) {
        return lxmCommentService.listByUserId(current);
    }

    @Operation(summary = "分页获取博客、商品的评论列表",
            description = "这个用于用户查看博客时查询评论列表，返回的是详细的评论内容、" +
                    "第一次直接从内部方法里面走的，后面则是正常获取分页的评论数据")
    @GetMapping("/list/detail/{Id}/{commentType}")
    public Result getDetailCommentList(@PathVariable("Id") Long Id,
                                       @PathVariable("commentType") Integer commentType,
                                       @RequestParam(name = "current", defaultValue = "2")
                                       Integer current) {
        List<CommentDetailVO> detailCommentList = lxmCommentService
                .getDetailCommentList(Id, commentType, current);
        return Result.ok(detailCommentList);
    }


}

